package com.kaibes.web.request;

import java.io.ByteArrayInputStream;
import java.io.IOException;

import javax.servlet.ReadListener;
import javax.servlet.ServletInputStream;

public class ByteServletInputStream extends ServletInputStream {

    private ByteArrayInputStream bais;
    private int i = 0;

    public ByteServletInputStream(byte[] body) {
        bais = new ByteArrayInputStream(body);
    }

    @Override
    public boolean isFinished() {
        return i == -1;
    }

    @Override
    public boolean isReady() {
        return i > -1;
    }

    @Override
    public void setReadListener(ReadListener readListener) {
    }

    @Override
    public int read() throws IOException {
        i = bais.read();
        return i;
    }

}
